package com.it.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @Author: CaoYouGen
 * @DateTime: 2023/11/09/10:22
 * @注释: TODO
 **/
@RestController
@RequestMapping("/getLogin")
public class CurrentLoginUserController {

    @GetMapping("/user1")
    public Authentication getUser1(Authentication authentication) {
        return authentication;
    }

    @GetMapping("/user2")
    public Principal getUser2(Principal principal){
        return principal;
    }

    @GetMapping("/user3")
    public Principal getUser3(){
        // 通过安全上下文持有器获取安全上下文，再获取认证信息
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
